package net.huashitong.synthetical.showView.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.gis.entity.InterviewRegister;
import net.huashitong.gis.service.RegisterService;
import net.huashitong.synthetical.showView.filter.ProjectFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static net.huashitong.synthetical.showView.util.DataTimeUtil.strToDateFormat;

/**
 * 走访控制器
 */
@Controller
@RequestMapping("/interview")
public class InterViewCtrl extends JsonBaseController {

    @Autowired
    private RegisterService service;
    @Override
    protected String getView(String s) {
        return null;
    }


    /**
     * 县领导走访企业情况
     * @param filter
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/interviewdetail",method = RequestMethod.POST)
    public Message getInterViewDetail(@RequestBody ProjectFilter filter) throws ParseException {
        //通过企业关键词，查询跟企业相关的走访信息
        String enterpriseName = filter.getEnterpriseName();        //企业名称
        if(StringUtils.isBlank(enterpriseName)){
            enterpriseName = "中海创";
        }
        List<InterviewRegister> interviewRegisterList = service.queryByEnterpriseNameVague(enterpriseName);
        if(interviewRegisterList.size()>0){
            InterviewRegister register = interviewRegisterList.get(0);
            Map<String,Object> map = new HashMap<>();
            map.put("sysId",register.getSysId());
            map.put("fillUnitId", ObjectUtils.isNotBlank(register.getFillUnitId())?register.getFillUnitId():"-");
            map.put("userName",ObjectUtils.isNotBlank(register.getUserName())?register.getUserName():"-");
            map.put("contactBusiness",ObjectUtils.isNotBlank(register.getContactBusiness())?register.getContactBusiness():"-");
            map.put("interviewCountThisMonth",ObjectUtils.isNotBlank(register.getInterviewCountThisMonth())?register.getInterviewCountThisMonth():"-");
            map.put("businessProblem",ObjectUtils.isNotBlank(register.getBusinessProblem())?register.getBusinessProblem():"-");
            map.put("solveState",ObjectUtils.isNotBlank(register.getSolveState())?register.getSolveState():"-");
            map.put("fillDate",strToDateFormat(ObjectUtils.isNotBlank(register.getFillDate())?register.getFillDate():"-"));
            map.put("helpExperience",ObjectUtils.isNotBlank(register.getHelpExperience())?register.getHelpExperience():"-");
            return coverMessage("200","获取成功",map);
        }else{
            Map<String,Object> map = new HashMap<>();
            map.put("sysId","-");
            map.put("fillUnitId", "-");
            map.put("userName","-");
            map.put("contactBusiness","-");
            map.put("interviewCountThisMonth","-");
            map.put("businessProblem","-");
            map.put("solveState","-");
            map.put("fillDate","-");
            map.put("helpExperience","-");
            return coverMessage("200","获取成功",map);
        }
    }
}
